import React, { Component } from 'react';
import ReactDom from 'react-dom';

import LxHeader from './components/LxHeader';
import LxList from './components/LxList';

import './app.less';
import axios from 'axios';

import jssdk from './utils/jsbridge-sdk';

console.log(jssdk);

// 添加jssdk的方法
jssdk.addClientMethod(["jsMethod"]);
jssdk.addMethod(["btnClick", "getVersion"])

jssdk.ready(function (sdk) {

    class App extends Component {
        constructor(props) {
            super(props);

            this.handleBtnClick = this.handleBtnClick.bind(this);

            this.state = {
                books: []
            }
        }

        componentDidMount() {
            if (sdk.jsMethod){
                sdk.jsMethod(function (data, responseCallback){
                   console.log(data);
                   if (responseCallback){
                       responseCallback("js得到了" + data +",请Android知晓");
                   }
               });
           }
        }

        handleBtnClick(){
            if (sdk.btnClick){
                sdk.btnClick({'Ok':'成功!!!'}, function (res){
                    console.log('Android端响应------->' + res);
                });
            }
        }

        render() {
            let { books } = this.state;
            return (
                <div>
                    <LxHeader></LxHeader>
                    <p className="red">
                        hello react!!!
                    </p>

                    <img width="100" height="100" src={require('./assets/006.jpg')} />
                    <button className="btn" onClick={this.handleBtnClick}>点击</button>
                    <LxList books={books}></LxList>
                </div>
            )
        }
    }

    ReactDom.render(<App />, document.getElementById('app'));
});



